package com.wuyu.mini.singleton;

/**
 * 单例最佳实践，JVM对于枚举类型只能实例化一次
 */
public class Singleton {

    public static Singleton getInstance(){
        return SingleTonEnum.SINGLETON.getInstance();
    }

    private enum SingleTonEnum{
        SINGLETON;
        private Singleton instance;

        /**
         * 只会执行一次
         */
        SingleTonEnum(){
            instance = new Singleton();
        }
        public Singleton getInstance(){
            return this.instance;
        }
    }
}
